package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.Collectionrecord;
import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.service.CollectionRecordService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class CollectionRecordController {
    @Autowired
    CollectionRecordService collectionRecordService;
    @Autowired
    HttpSession session;
    //分页查询所有回款记录
    /*@RequestMapping("/emp-collectionrecord-list")
    @ResponseBody
    public Map<String,Object> CollectionRecordList(Integer page, Integer size){
        Employee emp = (Employee) session.getAttribute("emp");
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Collectionrecord> collectionrecords = collectionRecordService.selectEmpCollectionRecord(emp.getEmpId());
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",collectionrecords);
        return map;
    }*/
    @RequestMapping("/emp-collectionrecord-list")
    @ResponseBody
    public Map<String,Object> CollectionRecordList(Integer page, Integer size,Integer value,Integer num,Integer vague,String content) {
        Employee emp = (Employee) session.getAttribute("emp");
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Collectionrecord> coll = collectionRecordService.selectEmpCollectionRecord(emp.getDepartment().getDeptId(),emp.getEmpId(),value,num,vague,content);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",coll);
        return map;
    }
    //按合同订单id查询回款记录
    @RequestMapping("/back-records-con-list")
    @ResponseBody
    public List<Collectionrecord> backRecordsDateList(Integer conId){
        List<Collectionrecord> col = collectionRecordService.selectCollectionRecordsByConId(conId);
        return col;
    }

    //按付款方式查询
    @RequestMapping("/emp-collectionrecord-paystyle-list")
    @ResponseBody
    public Map<String,Object> CollectionRecordListByPays(Integer page, Integer size,Integer collectionrecordPaystyle){
        Employee emp = (Employee) session.getAttribute("emp");
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Collectionrecord> collectionrecords = collectionRecordService.selectEmpCollectionRecordByPays(emp.getDepartment().getDeptId(),collectionrecordPaystyle);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",collectionrecords);
        return map;
    }
    //按分类查询
    @RequestMapping("/emp-collectionrecord-sort-list")
    @ResponseBody
    public Map<String,Object> CollectionRecordListBySort(Integer page, Integer size,Integer collectionrecordSort){
        Employee emp = (Employee) session.getAttribute("emp");
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Collectionrecord> collectionrecords = collectionRecordService.selectEmpCollectionRecordBySort(emp.getDepartment().getDeptId(),collectionrecordSort);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",collectionrecords);
        return map;
    }
    //按开票查询
    @RequestMapping("/emp-collectionrecord-invoice-list")
    @ResponseBody
    public Map<String,Object> CollectionRecordListByInvoiced(Integer page, Integer size,Integer collectionrecordInvoiced){
        Employee emp = (Employee) session.getAttribute("emp");
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Collectionrecord> collectionrecords = collectionRecordService.selectEmpCollectionRecordByInvoiced(emp.getDepartment().getDeptId(),collectionrecordInvoiced);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",collectionrecords);
        return map;
    }
    //按退款查询
    //按回款日期查询
    @RequestMapping("/emp-collectionrecord-date-list")
    @ResponseBody
    public Map<String,Object> CollectionRecordListByDate(Integer page, Integer size,String collectionrecordDate){
        Employee emp = (Employee) session.getAttribute("emp");
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Collectionrecord> collectionrecords = collectionRecordService.selectEmpCollectionRecordByDate(emp.getDepartment().getDeptId(),collectionrecordDate);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",collectionrecords);
        return map;
    }
    //按客户名称查询
    @RequestMapping("/emp-collectionrecord-customerName-list")
    @ResponseBody
    public Map<String,Object> CollectionRecordListByCusName(Integer page, Integer size,String customerName){
        Employee emp = (Employee) session.getAttribute("emp");
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Collectionrecord> collectionrecords = collectionRecordService.selectEmpCollectionRecordByCusName(emp.getDepartment().getDeptId(),customerName);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",collectionrecords);
        return map;
    }
    //新增与修改
    @RequestMapping("/save-collectionrecord")
    @ResponseBody
    public void saveCollectionRecords(@RequestBody Collectionrecord collectionrecord ){
        collectionRecordService.saveCollectionRecords(collectionrecord);
    }
    //删除
    @RequestMapping("/delete-collectionrecord")
    @ResponseBody
    public void deleteCollectionRecords(@RequestParam(value = "collectionrecordId") Integer collectionrecordId){
        collectionRecordService.deleteCollectionRecords(collectionrecordId);
    }
}
